﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kokomo.Lexical.Expressions;
using System.Reflection.Emit;

namespace Kokomo.PeInspector.Reflection.Disassembly
{
	/// <summary>
	/// Describes a transition within anMSIL procedure.
	/// </summary>
	/// <remarks>
	/// A transition is an aberration from the normal flow of execution.
	/// </remarks>
	/// <seealso cref="MsilBranch"/>
	/// <seealso cref="MsilSwitch"/>
	public class MsilTransition
	{
		/// <summary>
		/// Gets the offset of the source of the transition.
		/// </summary>
		public int SourceOffset { get; private set; }
		/// <summary>
		/// Gets a value indicating whether the transition is conditional.
		/// </summary>
		public bool IsConditional { get; private set; }

		/// <summary>
		/// Initializes a new instance of <see cref="MsilTransition"/>.
		/// </summary>
		/// <param name="sourceOffset">The offset of the source of the transition.</param>
		/// <param name="type">The type of transition.</param>
		protected MsilTransition(
			int sourceOffset,
			bool isConditional
			)
		{
			this.SourceOffset = sourceOffset;
			this.IsConditional = isConditional;
		}

		public override string ToString()
		{
			return string.Format("{0:X4}: {1}", this.SourceOffset, this.IsConditional ? "?" : null);
		}
	}
}
